home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 50
/
Volume 50 - JOGO DISK .iso
/
Games
/
lightsout.swf
/
scripts
/
frame_3
/
DoAction.as
Wrap
Text File
|
2007-10-01
|
15KB
|
533 lines
function buildCube(cubeToBuild)
{
layersY = [];
_root.attachMovie("empty","cube",1);
layer = 0;
while(layer < cubeToBuild.length)
{
cube.attachMovie("empty","layer_" + layer,layer);
layerWidth = cubeToBuild[layer].length;
layerHeight = cubeToBuild[layer][0].length;
game.clip = cube["layer_" + layer];
game.clip._y = (- layer) * game.tileW - (400 + layer * 2500);
layersY.push((- layer) * game.tileW);
x = 0;
while(x < layerWidth)
{
y = 0;
while(y < layerWidth)
{
name = "t_" + x + "_" + y;
frame = cubeToBuild[layer][x][y];
depth = (y + x) * game.tileW / 2 * 300 + (y - x) * game.tileW + 1;
game.clip.attachMovie("tile",name,depth);
game.clip[name]._x = (y - x) * game.tileW;
game.clip[name]._y = (y + x) * game.tileW / 2;
game.clip[name].gotoAndStop(frame);
game.clip[name].select.gotoAndStop("off");
y++;
}
x++;
}
layer++;
}
cube._x = Stage.width / 2;
cube._y = Stage.height / 2;
game.active = true;
}
function detectKeys()
{
if(Key.isDown(17))
{
game.currentLayer = 0;
moveLayers();
}
else if(Key.isDown(16))
{
game.currentLayer = 1;
moveLayers();
}
else
{
game.currentLayer = 2;
}
}
function makeMove()
{
x = Number(game.currentTile.substr(24,1));
y = Number(game.currentTile.substr(26,1));
l = Number(game.currentTile.substr(20,1));
if(game.Mode == "makeCustom")
{
tile = cube["layer_" + l]["t_" + x + "_" + y];
frame = tile._currentframe;
if(frame == 1)
{
tile.gotoAndStop("on");
}
else
{
tile.gotoAndStop("off");
}
}
else
{
if(game.Mode != "random")
{
light_sound.start();
}
tile1 = cube["layer_" + l]["t_" + x + "_" + y];
tile2 = cube["layer_" + l]["t_" + (x + 1) + "_" + y];
tile3 = cube["layer_" + l]["t_" + (x - 1) + "_" + y];
tile4 = cube["layer_" + l]["t_" + x + "_" + (y + 1)];
tile5 = cube["layer_" + l]["t_" + x + "_" + (y - 1)];
tile6 = cube["layer_" + (l + 1)]["t_" + x + "_" + y];
tile7 = cube["layer_" + (l - 1)]["t_" + x + "_" + y];
i = 1;
while(i <= 7)
{
tile = _root["tile" + i];
if(tile != undefined)
{
frame = tile._currentframe;
if(frame == 1)
{
tile.gotoAndStop("on");
}
else
{
tile.gotoAndStop("off");
}
}
i++;
}
if(game.Mode != "random")
{
game.totalMoves = game.totalMoves + 1;
info.moves.text = game.totalMoves;
}
if(checkForWin() && game.Mode != "random")
{
Quit._y -= 100;
Reset._y -= 100;
info._y -= 100;
removeMovieClip(cube);
_root.attachMovie("win_page","winPage",1000);
winPage._x = Stage.width / 2;
winPage._y = Stage.height / 2;
game.currentScore = 300;
if(game.Mode == "normal")
{
winPage.gotoAndStop(1);
winPage.score.text = game.currentScore;
winPage.moves.text = game.totalMoves;
winPage.total.text = game.totalScore;
pauseT = 50;
scoreTicker = setInterval(calcScore,10);
}
else if(game.Mode == "playCustom")
{
winPage.gotoAndStop(2);
winPage.moves.text = game.totalMoves;
winPage.btn.onRelease = function()
{
Quit.btn.onRelease();
};
}
else if(game.Mode == "playRandom")
{
winPage.gotoAndStop(2);
winPage.moves.text = game.totalMoves;
winPage.btn.onRelease = function()
{
Quit.btn.onRelease();
};
}
}
}
}
function calcScore()
{
game.overallMoves += game.totalMoves;
if(pauseT > 0)
{
pauseT--;
}
else
{
if(game.currentScore > 0)
{
game.currentScore--;
game.totalScore = game.totalScore + 1;
winPage.score.text = game.currentScore;
winPage.total.text = game.totalScore;
}
else if(game.totalMoves > 0)
{
game.totalMoves--;
game.totalScore -= 5;
winPage.moves.text = game.totalMoves;
winPage.total.text = game.totalScore;
}
winPage.btn.onRelease = function()
{
game.totalScore += game.currentScore;
game.totalMoves = 0;
game.currentScore = 0;
info.moves.text = game.totalMoves;
clearInterval(scoreTicker);
game.currentMap = game.currentMap + 1;
if(_root["cubeMap" + game.currentMap] != undefined)
{
Quit._y += 100;
Reset._y += 100;
info._y += 100;
saveFile.data.currentMap = game.currentMap;
saveFile.data.totalScore = game.totalScore;
saveFile.flush();
buildCube(_root["cubeMap" + game.currentMap]);
removeMovieClip(winPage);
info.lvl.text = game.currentMap;
info.score.text = game.totalScore;
}
else
{
winPage.gotoAndStop(3);
winPage.score.text = game.totalScore;
winPage.moves.text = game.overallMoves;
winPage.go_btn.onRelease = function()
{
removeMovieClip(cube);
removeMovieClip(winPage);
removeMovieClip(Quit);
_root.gotoAndStop("menu");
};
winPage.submit_btn.onRelease = function()
{
sendScore();
winPage.go_btn.onRelease();
};
}
};
}
}
function checkForWin()
{
if(game.Mode == "normal" || game.Mode == "playRandom")
{
l = 0;
while(l < _root["cubeMap" + game.currentMap].length)
{
x = 0;
while(x < layerWidth)
{
y = 0;
while(y < layerWidth)
{
name = "t_" + x + "_" + y;
tile = cube["layer_" + l]["t_" + x + "_" + y];
if(tile._currentframe == 2)
{
return false;
}
y++;
}
x++;
}
l++;
}
return true;
}
l = 0;
while(l < game.currentMap.length)
{
x = 0;
while(x < layerWidth)
{
y = 0;
while(y < layerWidth)
{
name = "t_" + x + "_" + y;
tile = cube["layer_" + l]["t_" + x + "_" + y];
if(tile._currentframe == 2)
{
return false;
}
y++;
}
x++;
}
l++;
}
return true;
}
function getCustomMap()
{
tempMap = [];
tempLayer = [];
l = 0;
while(l < 3)
{
x = 0;
while(x < 3)
{
tempColl = [];
y = 0;
while(y < 3)
{
tile = cube["layer_" + l]["t_" + x + "_" + y];
tempColl.push(tile._currentframe);
y++;
}
tempLayer.push(tempColl);
x++;
}
tempRow = [];
tempMap.push(tempLayer);
tempLayer = [];
l++;
}
return tempMap;
}
function saveCustomMap(mapNumber, mapName)
{
errorMessage.display_txt.text = "*Scanning current map*";
mapArray = getCustomMap();
errorMessage.display_txt.text = "*saving out map data...*";
_root["customMap" + mapNumber] = new Object();
_root["customMap" + mapNumber].name = mapName;
_root["customMap" + mapNumber].map = mapArray;
saveFile.data["customMapName" + mapNumber] = name;
saveFile.data["customMapArray" + mapNumber] = _root["customMap" + mapNumber].map;
errorMessage.display_txt.text = "*Map Data saved successfully*";
errorMessage.play();
saveFile.data["customMapName" + mapNumber] = mapName;
saveFile.data["customMapArray" + mapNumber] = _root["customMap" + mapNumber].map;
saveFile.flush();
savePage.cancel_btn.onRelease();
}
function sendScore()
{
var _loc3_ = "http://localhost/gameTest2/lightOut_highscores.php?task=submit&user=" + winPage.user.text + "&score=" + game.totalScore;
var _loc2_ = new LoadVars();
_loc2_.onLoad = function(success)
{
if(success)
{
removeMovieClip(cube);
removeMovieClip(winPage);
removeMovieClip(Quit);
_root.gotoAndStop("menu");
}
else
{
errorMessage.display_txt.text = "*Error occured when sending score*";
errorMessage.play();
}
};
}
function randomMoves()
{
moveTotal = Math.ceil(Math.random() * 10) + 6;
m = 0;
while(m < moveTotal)
{
ranX = Math.ceil(Math.random() * 2);
ranY = Math.ceil(Math.random() * 2);
ranZ = Math.ceil(Math.random() * 2);
tile = _level0.cube["layer_" + ranZ]["t_" + ranX + "_" + ranY];
game.currentTile = tile;
makeMove();
m++;
}
randomArray = getCustomMap();
game.Mode = "playRandom";
}
cubeMap0 = [[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]];
cubeMap1 = [[[2,1,2],[1,1,1],[2,1,2]],[[1,1,1],[1,1,1],[1,1,1]],[[2,1,2],[1,1,1],[2,1,2]]];
cubeMap2 = [[[2,1,1],[2,2,2],[1,1,2]],[[1,1,2],[1,2,1],[2,1,1]],[[2,1,1],[2,2,2],[1,1,2]]];
cubeMap3 = [[[1,1,1],[1,2,1],[1,1,2]],[[1,1,2],[1,2,2],[2,2,2]],[[1,2,1],[2,2,1],[1,1,2]]];
cubeMap4 = [[[1,1,1],[1,1,1],[1,1,1]],[[1,1,2],[1,1,1],[2,1,2]],[[1,1,1],[1,1,1],[1,1,1]]];
cubeMap5 = [[[1,1,1],[1,1,1],[1,1,1]],[[1,2,1],[2,1,2],[1,2,1]],[[1,1,1],[1,1,1],[1,1,1]]];
cubeMap6 = [[[2,2,2],[2,1,2],[2,2,2]],[[2,2,2],[2,1,2],[2,2,2]],[[2,2,2],[2,1,2],[2,2,2]]];
cubeMap7 = [[[1,1,1],[2,1,1],[1,1,1]],[[1,1,1],[1,2,1],[1,1,1]],[[1,1,1],[1,1,2],[1,1,1]]];
cubeMap8 = [[[1,1,2],[1,1,2],[2,2,1]],[[1,2,1],[2,1,1],[1,1,1]],[[1,1,2],[1,1,2],[2,2,1]]];
cubeMap9 = [[[2,2,2],[2,2,2],[2,2,2]],[[1,1,1],[1,2,1],[1,1,1]],[[2,2,2],[2,2,2],[2,2,2]]];
cubeMap10 = [[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,2,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]];
cubeMap11 = [[[2,1,2],[1,2,1],[2,1,2]],[[1,2,1],[2,2,2],[1,2,1]],[[2,1,2],[1,2,1],[2,1,2]]];
cubeMap12 = [[[2,1,1],[1,1,1],[1,1,2]],[[2,2,2],[2,1,2],[2,2,2]],[[1,1,2],[1,1,1],[2,1,1]]];
cubeMap13 = [[[2,1,2],[1,1,1],[2,1,2]],[[2,1,1],[1,2,1],[1,1,2]],[[2,1,2],[1,1,1],[2,1,2]]];
cubeMap14 = [[[2,2,2],[2,2,2],[2,2,2]],[[2,1,2],[2,1,2],[2,1,2]],[[2,2,2],[2,2,2],[2,2,2]]];
cubeMap15 = [[[2,1,1],[1,1,1],[2,1,2]],[[1,2,2],[2,1,2],[2,2,1]],[[2,1,2],[1,1,1],[1,1,2]]];
cubeMap16 = [[[2,1,2],[1,1,1],[2,1,2]],[[2,1,2],[1,1,1],[2,1,2]],[[1,1,1],[2,2,2],[1,1,1]]];
if(game.Mode == "playCustom")
{
buildCube(game.currentMap);
}
else if(game.Mode == "normal")
{
buildCube(_root["cubeMap" + game.currentMap]);
}
else if(game.Mode == "makeCustom")
{
buildCube(cubeMap0);
}
else if(game.Mode == "random")
{
buildCube(cubeMap0);
randomMoves();
}
onEnterFrame = function()
{
detectKeys();
if(game.active)
{
dy3 = cube.layer_0._y - layersY[0];
if(dy3 < 0)
{
cube.layer_0._y -= dy3 * 0.1;
}
else
{
cube.layer_0._y = layersY[0];
}
if(game.currentLayer == 0)
{
dy = cube.layer_2._y - (layersY[2] - 120);
if(dy > 0)
{
cube.layer_2._y -= dy * 0.1;
}
else
{
cube.layer_2._y = layersY[2] - 120;
}
dy2 = cube.layer_1._y - (layersY[1] - 120);
if(dy2 > 0)
{
cube.layer_1._y -= dy2 * 0.1;
}
else
{
cube.layer_1._y = layersY[1] - 120;
}
}
else if(game.currentLayer == 1)
{
dy = cube.layer_2._y - (layersY[2] - 120);
if(dy > 0)
{
cube.layer_2._y -= dy * 0.1;
}
else
{
cube.layer_2._y = layersY[2] - 120;
}
dy2 = cube.layer_1._y - layersY[1];
if(dy2 < 0)
{
cube.layer_1._y -= dy2 * 0.1;
}
else
{
cube.layer_1._y = layersY[1];
}
}
else if(game.currentLayer == 2)
{
dy = cube.layer_2._y - layersY[2];
if(dy < 0)
{
cube.layer_2._y -= dy * 0.1;
}
else
{
cube.layer_2._y = layersY[2];
}
dy2 = cube.layer_1._y - layersY[1];
if(dy2 < 0)
{
cube.layer_1._y -= dy2 * 0.1;
}
else
{
cube.layer_1._y = layersY[1];
}
}
}
};
saveCustom.btn.onRelease = function()
{
_root.attachMovie("save_page","savePage",100);
savePage._x = Stage.width / 2;
savePage._y = Stage.height / 2;
saveCustom._y -= 100;
i = 1;
while(i < 6)
{
list = savePage["name" + i];
if(_root["customMap" + i].name != undefined)
{
list.text = _root["customMap" + i].name;
}
i++;
}
savePage.btn1.onRelease = function()
{
saveCustomMap(1,savePage.name1.text);
};
savePage.btn2.onRelease = function()
{
saveCustomMap(2,savePage.name2.text);
};
savePage.btn3.onRelease = function()
{
saveCustomMap(3,savePage.name3.text);
};
savePage.btn4.onRelease = function()
{
saveCustomMap(4,savePage.name4.text);
};
savePage.btn5.onRelease = function()
{
saveCustomMap(5,savePage.name5.text);
};
savePage.cancel_btn.onRelease = function()
{
removeMovieClip(savePage);
saveCustom._y += 100;
};
};
Quit.btn.onRelease = function()
{
removeMovieClip(cube);
removeMovieClip(Quit);
removeMovieClip(Reset);
removeMovieClip(info);
removeMovieClip(saveCustom);
removeMovieClip(savePage);
removeMovieClip(winPage);
gotoAndStop("menu");
};
Reset.btn.onRelease = function()
{
game.totalMoves = 0;
info.moves.text = "0";
if(game.Mode == "playCustom")
{
buildCube(game.currentMap);
}
else if(game.Mode == "normal")
{
buildCube(_root["cubeMap" + game.currentMap]);
}
else if(game.Mode == "makeCustom")
{
buildCube(cubeMap0);
}
else if(game.Mode == "playRandom")
{
buildCube(randomArray);
}
};